package data;

import java.awt.Color;
import java.awt.Font;
import java.awt.FontFormatException;
import java.awt.Frame;
import java.awt.Image;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import com.meg.swing_utils.graphics.AWTLoader;

import data.conference.Conference;

/**
 * A static container of all resources used by the CMS application.
 * 
 * @author Chris Molini
 */
public class CMSRes
{
	private CMSRes() { }
	
	private static Frame frame;
	public static Frame frame() { return frame; }
	
	private static Conference conference;
	public static Conference conference() { return conference; }
	public static void setConference(Conference c) { conference = c; }
	
	private static ClassLoader cL = CMSRes.class.getClassLoader();
	
	public static void init(Frame appFrame)
	{
		frame = appFrame;
		Colors.init();
		Images.init();
		Fonts.init();
	}
	
	public static class Fonts
	{
		private static Map<String, Font> fontMap;
		
		private Fonts() { }
		
		private static void init()
		{
			fontMap = new HashMap<String, Font>();
			registerFont("Nametag Title", "res/fonts/Freeroad.ttf", 48, Font.BOLD);
			registerFont("Nametag Text", "res/fonts/Sansation_Regular.ttf", 36, Font.BOLD);
		}
		
		public static void registerFont(String name, String path, float size, int style)
		{
			try
			{
				Font font = Font.createFont(Font.TRUETYPE_FONT, cL.getResourceAsStream(path));
				font = font.deriveFont(size);
				font = font.deriveFont(style);
				fontMap.put(name, font);
			}
			catch (FontFormatException e) { e.printStackTrace(); }
			catch (IOException e) { e.printStackTrace(); }
		}
		
		public static Font get(String font) { return fontMap.get(font); }
	}
	
	public static class Colors
	{
		private static Map<String, Color> colorMap;
		
		private Colors() { }
		
		private static void init()
		{
			colorMap = new HashMap<String, Color>();
			register("Theme Color Light", 143, 176, 222);
			register("Theme Color Medium", 61, 120, 169);
			register("Theme Color Dark", 43, 86, 144);

			register("Admin Color Light", 224, 141, 141);
			register("Admin Color Medium", 174, 55, 55);
			register("Admin Color Dark", 124, 31, 31);
		}
		
		public static void register(String name, int r, int g, int b)
		{
			colorMap.put(name, new Color(r, g, b));
		}
		
		public static Color get(String name) { return colorMap.get(name); }
	}
	
	public static class Images
	{
		private static Map<String, Image> imageMap;
		
		private Images() { }
		
		private static void init()
		{
			imageMap = new HashMap<String, Image>();
			register("Background Title", "res/images/Background Title.png");
			register("Decor 1", "res/images/Background Decor 1.png");
			register("Decor 2", "res/images/Background Decor 2.png");
			register("Decor 3", "res/images/Background Decor 3.png");
			register("Admin Title", "res/images/Admin Background Title.png");
			register("Admin Decor 1", "res/images/Admin Decor 1.png");
			register("Admin Decor 2", "res/images/Admin Decor 2.png");
			register("Admin Decor 3", "res/images/Admin Decor 3.png");
		}
		
		public static void register(String image, String path)
		{
			imageMap.put(image, AWTLoader.loadImage(path, cL));
		}
		
		public static Image get(String image) { return imageMap.get(image); }
	}
}